﻿//
// Copyright (c) 2024 BPer
//
#include <bperdecoder/BPerDecoderFactory.h>
#include <bperdecoder/BPerH264DecoderSoftFactory.h>
#include <bperdecoder/BPerAudioDecoderOpus.h>
#include <bperdecoder/BPerH264DecoderSoft.h>
#include <bperdecoder/BPerDecoderOpenh264.h>

#if BPer_OS_ANDROID
#include <bperdecoder/BPerDecoderMediacodec.h>
#else
#include <bperdecoder/pc/BPerAudioDecoderAac.h>
#include <bperdecoder/pc/BPerAudioDecoderSpeex.h>
#include <bperdecoder/pc/BPerVideoDecoderFfmpeg.h>
#endif


BPerDecoderFactory::BPerDecoderFactory() {


}

BPerDecoderFactory::~BPerDecoderFactory() {

}

BPerAudioDecoder *BPerDecoderFactory::createAudioDecoder(BPerAudioCodec paet,BPerAudioParam *pcontext){

#if  !BPer_OS_ANDROID
	if(paet==BPer_AED_SPEEX) return new BPerAudioDecoderSpeex(pcontext);
	if(paet==BPer_AED_AAC) return new BPerAudioDecoderAac(pcontext);
#endif
	return new BPerAudioDecoderOpus(pcontext);
}

BPerAudioDecoder *BPerDecoderFactory::createAudioDecoder(BPerAudioParam *pcontext){


	return createAudioDecoder(pcontext->encode,pcontext);
}
#if !BPer_OS_ANDROID
BPerVideoDecoder* BPerDecoderFactory::createFfmpegVideoDecoder(BPerVideoCodec paet,BPerVideoInfo *pcontext){
#if BPer_Enable_Ffmpeg_Codec
	return new BPerVideoDecoderFfmpeg(pcontext,paet);
#else
	return NULL;
#endif
}
#endif
BPerVideoDecoder* BPerDecoderFactory::createVideoDecoder(BPerVideoCodec paet,BPerVideoInfo *pcontext){

#if BPer_OS_ANDROID
	if(pcontext->videoDecHwType==0)
		return new BPerH264DecoderSoft();
	else
		return new BPerDecoderMediacodec(pcontext,paet);
#else
	if (paet == BPer_VED_H264)				{
		if(pcontext->videoDecHwType==0){
#if	BPer_Enable_H264Decoder
			return new BPerH264DecoderSoft();
#else
			return new BPerVideoDecoderFfmpeg(pcontext,paet);
#endif
		}else{
#if BPer_Enable_Ffmpeg_Codec
			return new BPerVideoDecoderFfmpeg(pcontext,paet);
#else
			return NULL;
#endif
		}
	}
#if BPer_Enable_Ffmpeg_Codec
	if (paet == BPer_VED_H265)				return new BPerVideoDecoderFfmpeg(pcontext,paet);
#endif
#endif
	return NULL;
}
BPerVideoDecoder* BPerDecoderFactory::createVideoDecoder(BPerVideoInfo *pcontext){
	BPerVideoCodec maet=BPer_VED_H264;
	if(pcontext->videoDecoderType==BPer_VED_H265) maet=BPer_VED_H265;
	return createVideoDecoder(maet,pcontext);
}
